home *** CD-ROM | disk | FTP | other *** search
/ Power Tools for Macintosh / Power Tools for Macintosh (SoftBit)(1992).iso / Applications / Alpha 4.01 / LaTeX / Using MPW < prev   
Internet Message Format  |  1991-10-10  |  4KB

  1. From @cunyvm.cuny.edu:MPARK@UTMEM1.BITNET Wed Oct  9 15:17:52 1991
  2. Message-Id: <9110092017.AA19098@rice.edu>
  3. Date:     Wed, 9 Oct 91 15:16 CST
  4. From: <MPARK%UTMEM1.BITNET@cunyvm.cuny.edu>
  5. Subject:  MPW ACMDs
  6. To: pete@rice.edu
  7. X-Original-To:  pete@rice.edu, MPARK
  8.  
  9.  
  10. Pete,
  11.  
  12. The following summarizes a few hours of working through how to
  13. write an ACMD with MPW C.
  14.  
  15. Integers are 32 bits long in MPW C and passed as such in alert().
  16. Therefore, use %ld and %lu to print integers as in:
  17.  
  18.                 alert("defining CMLCol as %ld\n(k is %ld)",n,k);
  19.  
  20. Declaring or casting the parameters to short does not work as the
  21. standard conversion back to type int is done before passing them
  22. to alert.
  23.  
  24. The other callback functions work as documented.
  25.  
  26. To add an ACMD using MPW, compile and link following the directions
  27. for stand-alone code resources in the MPW C Compiler manual and
  28. chapter 8 of the MPW Reference manual. Briefly, compile with the
  29. -b option, so that all variables, including string constants, are
  30. compiled into the same segment. Access to them is via PC-relative
  31. addressing, so no special calls to create a dummy A5, or similar,
  32. world, are necessary. Link as shown, with the -rt, -m, and -sg
  33. options to name a the resource type and ID, specify the entry
  34. point, and name the segment. This method restricts greatly the
  35. number of library subroutines that can be used. More on how to
  36. use the DRVRruntime library to solve this comes later.
  37.  
  38. The following code does nothing but create, modify, and display
  39. an ACMD-defined variable.
  40.  
  41. /*---------------------------------------------------------------
  42.  
  43.         VarACMD, a code segment to access an ACMD-defined variable.
  44.  
  45.         Restrictions: Treatment of int as longs is MPW C specific.
  46.  
  47.         Compile with:
  48.  
  49.                 C -b 'VarACMD.c'
  50.  
  51.         Link with:
  52.  
  53.                 Link -t 'ACMD'  -rt ACMD=128 -m main -sg VarACMD 6
  54.                 'VarACMD.c.o' 6
  55.                 #"{CLibraries}"CSANELib.o 6
  56.                 #"{CLibraries}"Math.o 6
  57.                 #"{CLibraries}"Complex.o 6
  58.                 #"{CLibraries}"StdClib.o 6
  59.                 #"{Libraries}"Runtime.o 6
  60.                 #"{Libraries}"Interface.o 6
  61.                 -o VarACMD
  62.  
  63.         (Note that no libraries are needed for this little thing.)
  64.  
  65.         M.R. Park
  66.         Univ. Tenn. Memphis
  67.         (901) 528-5984
  68.         MPARK@utmem1.utmem.edu
  69.  
  70. ----------------------------------------------------------------*/
  71.  
  72.  
  73. typedef int (*FPtr)();
  74.  
  75. int MyGlobal;
  76.  
  77. char *main(char *text,FPtr alert,FPtr getVar,
  78.         FPtr setVar, FPtr defVar, FPtr delVar)
  79. {
  80.         int n,k;
  81.  
  82.         if (!(k=getVar("CMLCol",&n))) {
  83.                 defVar("CMLCol",n=1);
  84.                 alert("defining CMLCol as %ld\n(k is %ld)",n,k);
  85.         }
  86.         MyGlobal=k;
  87.         alert("bumping CMLCol from %ld to %ld\n (k is %ld)",n,n+1,MyGlobal);
  88.         if(!setVar("CMLCol",n+1))
  89.                 alert("Error\n");
  90.  
  91.         return text;
  92. }
  93.  
  94. /*--------------------------- END ------------------------------*/
  95.  
  96.  
  97. In the Alpha HelpText, I suggest modifying the first line of the
  98. explanation of each callback function:
  99.  
  100.  
  101. 1.   /***********************************************
  102.      *                                              *
  103.      * Returns the longword value of the variable   *
  104.  
  105. 2.   /***********************************************
  106.      *                                              *
  107.      * Set the longword value of the variable       *
  108.  
  109. 3.   /************************************************
  110.      *                                               *
  111.      * Define a longword variable named 'name' with  *
  112.  
  113. 4.   /*******************************************
  114.      *                                          *
  115.      * Delete a longword variable named 'name'. *
  116.  
  117.  
  118.  
  119.                 -Mel Park
  120.  
  121.  
  122.